package cn.ffcs.unm.cost.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.cost.dao.CostDao;
import cn.ffcs.unm.cost.model.DeptCost;
import cn.ffcs.unm.cost.model.TaxGroup;
import cn.ffcs.unm.cost.model.TaxGroupMember;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("costDao")
public class CostDaoImpl extends BaseDaoImpl implements CostDao {

	@Override
	public PageInfo queryPageInfoByDeptCost(DeptCost deptCost, int currentPage,
			int pageSize) {

		StringBuilder sb = new StringBuilder();
		sb.append(" select  * from VIEW_DEPT_COST_CON where 1 = 1 ");
		
		List<Object> params = new ArrayList<Object>();

		if (null != deptCost) {
			if (!StrUtil.isEmpty(deptCost.getMonthId())) {
				sb.append(" AND V.monthId = ? ");
				params.add(deptCost.getMonthId());
			}
			if (!StrUtil.isEmpty(deptCost.getOrgName())) {
				sb.append(" AND V.orgName LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(deptCost.getOrgName())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, DeptCost.class);
	}

	@Override
	public PageInfo queryPageInfoByTaxGroup(TaxGroup taxGroup, int currentPage,
			int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_TAXGROUP  v where 1 = 1");
		List<Object> params = new ArrayList<Object>();
		if (null != taxGroup) {
			if (!StrUtil.isEmpty(taxGroup.getMonthId())) {
				sb.append(" AND v.MONTHID = ? ");
				params.add(taxGroup.getMonthId());
			}
			if (!StrUtil.isEmpty(taxGroup.getCGroupName())) {
				sb.append(" AND v.CGROUPNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(taxGroup.getCGroupName())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, TaxGroup.class);
	}

	@Override
	public PageInfo queryPageInfoByTaxGroupMember(TaxGroupMember taxGroupMember, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_TAXGROUPMEMBER where 1 = 1  ");
		List<Object> params = new ArrayList<Object>();
		if (null != taxGroupMember) {
			if (!StrUtil.isEmpty(taxGroupMember.getMonthId())) {
				sb.append(" and monthId = ? ");
				params.add(taxGroupMember.getMonthId());
			}
			/*if (!StrUtil.isEmpty(taxGroupMember.getCGroupName())) {
				sb.append(" AND ja1.CGROUPNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(taxGroupMember.getCGroupName())
						+ "%");
			}*/
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, TaxGroupMember.class);
	}

}
